package com.zzlzd.drp.domain;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Map;

/**
 * @author ceshi
 * @Title:
 * @Package
 * @Description:
 * @date 2021-3-1919:18
 */
public interface GoodsRep extends JpaRepository<GoodsDto,Integer> {

    @Query(nativeQuery=true, value=" select id,goods_name,goods_swiper,goods_img,goods_content,goods_sales,show_price,status,is_distribution,price_angel,price_city,price_province,price_partner,mid,sort,angel_price,city_price,province_price,partner_price,CASE ?2 WHEN 1 THEN angel_price WHEN 2 THEN city_price WHEN 3 THEN province_price WHEN 4 THEN partner_price ELSE goods_prices END goods_prices from goods WHERE `status` = 0 AND id = ?1")
    public GoodsDto findGoods(Integer id,int level);

    @Query(nativeQuery=true, value=" SELECT * FROM goods order by id")
    public List<GoodsDto> findAllGoods();

    @Query(nativeQuery=true, value=" SELECT g.*,m.menu_name FROM goods g LEFT JOIN goods_menu m on g.mid = m.id order by status, id desc ")
    public List<Map<String, Object>> findAlls();

    @Query(nativeQuery=true, value=" SELECT id,goods_name,goods_img,mid FROM goods WHERE mid = ?1 order by sort desc")
    List<Map<String, Object>> getGoodsMenuByMid(Integer id);

    @Query(nativeQuery=true, value=" SELECT * FROM goods WHERE is_distribution = 1")
    GoodsDto getIsDis();

    @Query(nativeQuery=true, value=" SELECT id,goods_name title,goods_img img, CASE ?1  When 1 THEN angel_price When 2 THEN city_price When 3 THEN province_price  When 4 THEN partner_price else goods_prices end price FROM goods WHERE `status` = 0 order by sort desc")
    List<Map<String, Object>> findListByASC(int level);
}
